package writtenexamination.weimeng.mianshi;

import java.util.ArrayList;
import java.util.Arrays;

/**
 * @author cyt
 * @create 2020-10-17 下午 7:11
 */
public class Ta {
    public static void main(String[] args) {
        Ta ta = new Ta();
        int[] a = {1, 3, 5, 7};
        int[] b = {2, 4, 8};
        int[] merge = ta.merge(a, b);
        for (int an : merge) {
            System.out.println(an);
        }
    }

    // a,b 都是从小到大已排序的数组，要求合并a和b，并将合并结果从小到大排序
    int[] merge(int[] a, int[] b) {
        ArrayList<Integer> list = new ArrayList<>();
        Arrays.stream(a).forEach((item) -> {
            list.add(item);
        });
        Arrays.stream(b).forEach((item) -> {
            list.add(item);
        });
        int[] ints = list.stream().mapToInt(Integer::intValue).sorted().toArray();
        return ints;
    }
}
